package streaming;

import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.Player;
import javax.media.TransitionEvent;

public class StateHelper implements ControllerListener{

	private Player entity;
	private int state;
	private Object lock = new Object();

	public synchronized boolean waitForState(Player entity, int state){
		this.entity = entity;
		this.state = state;

		try {
//			System.out.println("state helper blocked "  + entity);
			wait();
			return true;

		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		return false;
	}


	@Override
	public synchronized void controllerUpdate(ControllerEvent e) {

		if(e instanceof TransitionEvent){

			TransitionEvent event = (TransitionEvent)e;
			if(event.getCurrentState() == state){
				notify();
//				System.out.println("state helper unblocked: "  + entity);
			}
		}


	}
}
